package model

import "gorm.io/plugin/soft_delete"

const (
	DeptIdForRoot    = 1 // 部门根节点
	DeptIdForNothing = 2 // 未分配部门

	DeptStatusForOK      = 1 //正常
	DeptStatusForDisable = 2 //禁用

)

var DefaultDept = []Dept{
	{
		DeptId:         DeptIdForRoot,
		DeptName:       "总公司",
		ParentId:       0,
		MaxUserNum:     100,
		BalanceUserNum: 100,
		Status:         DeptStatusForOK,
		Creator:        "root",
		CreatorId:      RootId,
	},
	{
		DeptId:         DeptIdForNothing,
		DeptName:       "nothing",
		ParentId:       0,
		MaxUserNum:     100,
		BalanceUserNum: 100,
		Status:         DeptStatusForOK,
		Creator:        "root",
		CreatorId:      RootId,
	},
}

type Dept struct {
	DeptId         int64                 `json:"deptId,string" gorm:"primaryKey;comment:'部门id'"`
	ParentId       int64                 `json:"parentId,string" gorm:"comment:'父级id'"`
	DeptName       string                `json:"deptName" gorm:"comment:'部门名称'"`
	MaxUserNum     int                   `json:"maxUserNum" gorm:"comment:'部门最大用户数，'"`
	BalanceUserNum int                   `json:"balanceUserNum" gorm:"comment:'实际最大可支配用户数，每次添加和修改下级组织都会变动这个数值'"`
	Status         int                   `json:"status" gorm:"comment:'部门状态,1-正常；2-停用'"`
	Creator        string                `json:"creator" gorm:"comment:'创建者'"`
	CreatorId      int64                 `json:"creatorId,string" gorm:"comment:'创建者id'"`
	CreatedAt      int64                 `json:"createdAt,string" gorm:"autoCreateTime"`
	UpdatedAt      int64                 `json:"updatedAt,string" gorm:"autoUpdateTime"`
	DeletedAt      soft_delete.DeletedAt `json:"-"`
}

func (r *Dept) TableName() string {
	return "sys_dept"
}

type MapAppDept struct {
	AppId  int64 `json:"appId,string"`
	DeptId int64 `json:"deptId,string"`
}

func (r *MapAppDept) TableName() string {
	return "sys_map_app_dept"
}

type DeptForm struct {
	DeptId     int64  `json:"deptId,string"`
	ParentId   int64  `json:"parentId,string"`
	DeptName   string `json:"deptName" `
	MaxUserNum int    `json:"maxUserNum"`
	Status     int    `json:"status"`
}

type SearchDept struct {
	DeptName string `form:"deptName"`
}
